package com.adou.d15;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest4 {
    public static void main(String[] args) {
        List<Double> scores = new ArrayList<>();
        Collections.addAll(scores, 88.5, 100.0, 60.0, 99.0, 9.5, 99.6,  25.0);

        // 需求1：找出分数大于60分，并且升序排序，在输出
        scores.stream().filter(s->s>=60).sorted().forEach(s-> System.out.println(s));

        List<Student> stus = new ArrayList<>();
        Student stu1 = new Student("蜘蛛精", 26, 175.5);
        Student stu2 = new Student("蜘蛛精", 26, 175.5);
        Student stu3 = new Student("紫霞", 23, 167.6);
        Student stu4 = new Student("白晶晶", 25, 169.0);
        Student stu5 = new Student("牛魔王", 35, 183.3);
        Student stu6 = new Student("牛夫人", 34, 168.5);
        Collections.addAll(stus, stu1,stu2,stu3, stu4, stu5, stu6);

        // 需求2：年龄大于等于23,并且小于30，并降序输出
        stus.stream()
                .filter(s->s.getAge()>=23)
                .filter(s->s.getAge()<30)
                .sorted((o1, o2)->o2.getAge()-o1.getAge())
                .forEach(t-> System.out.println(t));

        // 需求3：取出身高最高的3名学生，并输出
        System.out.println("=====================================================");
        stus.stream()
                .sorted((o1,o2)->Double.compare(o2.getHeight(),o1.getHeight()))
                .limit(3) // 前3个
                .forEach(s-> System.out.println(s));

        // 需求4：取出身高最矮的2个学生，并输出
        System.out.println("===================================");
        stus.stream()
                .sorted((o1,o2)->Double.compare(o2.getHeight(),o1.getHeight()))
                .skip(stus.size()-2) // 跳过前面几个
                .forEach(s-> System.out.println(s));

        // 需求5：身高超过168学生的名字，并且去除重复的名字
        System.out.println("=========================================");
        stus.stream()
                .filter(t->t.getHeight()>168)
                .map(s->s.getName()).distinct()
                        .forEach(s-> System.out.println(s));


        // 需求5：身高超过168学生的名字，并且去除重复内容
        stus.stream()
                .filter(t->t.getHeight()>168)
                .map(s->s.getName()).distinct() // 去重复，自定义对象，重新hashCode equals
                .forEach(s-> System.out.println(s));


        Stream<String> s1 = Stream.of("a", "b");
        Stream<String> s2 = Stream.of("c", "d");
        Stream<String> concat = Stream.concat(s1, s2); // 类型不一样 需改Object


    }
}
